package com.fr.report.script.function;

import com.fr.base.FRContext;
import com.fr.report.script.Calculator;
import com.fr.report.script.Function;
import com.fr.report.script.Function.Type;
import com.fr.report.script.NormalFunction;
import com.fr.report.script.Primitive;
import com.fr.report.script.core.parser.UtilEvalError;
import java.util.logging.Level;
import java.util.logging.Logger;

public class EVAL extends NormalFunction
{
  public Object run(Object[] paramArrayOfObject)
  {
    if (paramArrayOfObject.length < 1)
      return Primitive.ERROR_NAME;
    Object localObject1 = paramArrayOfObject[0];
    Calculator localCalculator = getCalculator();
    Object localObject2 = null;
    if (localCalculator != null)
      try
      {
        localObject2 = localCalculator.eval(localObject1.toString());
      }
      catch (UtilEvalError localUtilEvalError)
      {
        FRContext.getLogger().log(Level.WARNING, localUtilEvalError.getMessage(), localUtilEvalError);
      }
    return ((localObject2 == null) ? Primitive.NULL : localObject2);
  }

  public Function.Type getType()
  {
    return Function.OTHER;
  }

  public String getCN()
  {
    return "EVAL(exp)返回表达式exp计算后的结果。\nexp:一个表达式形式字符串。\n备注:\n    只要EVAL中的参数exp最终可以转化成一表达式形式的字符串，比如\"sum(2,4)\",\"2+7\"等等，那么它就可以被计算。\nEVAL(\"2+5\")等于7。\nEVAL(\"count(2,3)\")等于5。\nEVAL(\"sum\"+\"(2,3,5)\")等于10。\nEVAL(IF(true, \"sum\", \"count\") + \"(1,2,3,4)\")等于10。\nEVAL(IF(false, \"sum\", \"count\") + \"(1,2,3,4)\")等于4。";
  }

  public String getEN()
  {
    return "";
  }
}